/**
 *  @file
 *  @brief   帽形（HAT）梁截面属性使用解析公式计算类
 *  @author  duweixing
 *  @date    2024.04.24
 *  @version v1.0
 *  @par Copyright(c):  ShenGong  Simulation corporation
 */

#include "HatSectionFormulaCalculator.h"
#include "DataStructure/Common/Real.h"

using SG::DataStructure::Common::Real;
using SG::DataStructure::FEM::PBARLData;
using SG::DataStructure::FEM::PBARData;
using SG::FEMSolver::Element::HatSectionFormulaCalculator;

void HatSectionFormulaCalculator::Compute
(
const SG::DataStructure::FEM::PBARLData& section,
_OUT SG::DataStructure::FEM::PBARData&   property,
_OUT SG::Algebra::Point&                 centroid
) const
{
    Real h{section.m_dimension[0]};
    Real t{section.m_dimension[1]};
    Real b{section.m_dimension[2]};
    Real b1{section.m_dimension[3]};
    Real b2{b - 2.0 * t};

    property.m_id  = section.m_id;
    property.m_mId = section.m_mId;
    property.m_A   = (b1 + h + b - 2.0 * t + h + b1) * t;
    // Real yS = (h - t) * (3.0 * (h - t) * b2 * b2 - 8.0 * b2 * b2 * b2) / (b2 * b2 * b2 + 6.0 * (h - t) * b2 * b2 +
    //           6.0 * (b1 + t) * b2 * b2 + 8.0 * (b1 + t) * (b1 + t) * (b1 + t) + 12.0 * b2 * (b1 + t) * (b1 + t)) + h - 0.5 * t;  // ToDo
    // Real zS = 0.0;
    Real yC = (b1 * t * t + t * h * h + b2 * t * (h - 0.5 * t)) / property.m_A;
    // Real zC = 0.0;
    property.m_I1  = (b1 * t * t * t / 12.0 + b1 * t * (yC - 0.5 * t) * (yC - 0.5 * t) +
                     t * h * h * h / 12.0 + t * h * (0.5 * h - yC) * (0.5 * h - yC)) * 2.0 +
                     b2 * t * t * t / 12.0 + b2 * t * (h - 0.5 * t - yC) * (h - 0.5 * t - yC);
    property.m_I2  = (t * b1 * b1 * b1 / 12.0 + t * b1 * 0.25 * (b + b1) * (b + b1) + h * t * t * t / 12.0 +
                     h * t * 0.25 * (b - t) * (b - t)) * 2.0 + t * b2 * b2 * b2 / 12.0;
    property.m_I12 = 0.0;
    property.m_J   = property.m_A * t * t / 3.0;
    property.m_K1  = 2.0 * (h - 2.0 * t) * t / property.m_A;
    property.m_K2  = (b1 + b - 2.0 * t + b1) * t / property.m_A;
    property.m_NSM = section.m_nsm;
    property.m_FE  = 0.0;
    property.SetStressPoints ({-yC + h,  0.5 * b,
                               -yC,      0.5 * b + b1,
                               -yC,     -0.5 * b - b1,
                               -yC + h, -0.5 * b});
    centroid.m_x = 0.0;
    centroid.m_y = 0.0;
    centroid.m_z = 0.0;
}